rm(list=ls())
install.packages("foreign")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("xlsx")

library(foreign)
library(ggplot2)
library(dplyr)
library(xlsx)

# Figure 2: Democratic vs. Republican president
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")


model.rep <- c("olspres_rep.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("olspres_dem.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add partyID variable
rep$Party <- "Republican president"
dem$Party <- "Democratic president"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$Party <- as.factor(mydata$Party)
mydata$Party <- factor(mydata$Party, levels = c(levels(mydata$Party)[2],levels(mydata$Party)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=Party)) + 
  geom_point(aes(x = order, y = pe, colour = Party), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig2 <- p + theme(legend.position = c(.83, 0.965),
               legend.background = element_rect(fill="transparent"),
               legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig2
ggsave("Figure2_Pres_Partisanship.pdf", width=9, height=8)


###########################################################

# Figure 3: Affectedness-based fairness: High vs. Low
model.a <- c("olsaff_norm_a.txt")
a <- read.table(model.a,header=TRUE)
a <- a[1:6,]

model.b <- c("olsaff_norm_d.txt")
b <- read.table(model.b,header=TRUE)
b <- b[1:6,]

c <- read.xlsx("olsaff_diff.xlsx", sheetIndex = 1)
rownames(c) <- c$NA.
c <- c[,c(2,3)]

# calculate standard errors
a$r1 <- sqrt(a$r1)
b$r1 <- sqrt(b$r1)
c$r1 <- sqrt(c$r1)

# calculate confidence intervals
a$lower <- a$y1  - 1.96*a$r1
a$upper <- a$y1  + 1.96*a$r1

b$lower <- b$y1  - 1.96*b$r1
b$upper <- b$y1  + 1.96*b$r1

c$lower <- c$y1  - 1.96*c$r1
c$upper <- c$y1  + 1.96*c$r1

colnames(a) <- c("pe", "se", "lower", "upper")
colnames(b) <- c("pe", "se", "lower", "upper")
colnames(c) <- c("pe", "se", "lower", "upper")

# extract relevant rows from c
c <- c[c(10,12,14,20),]

# add order variable 
a$order <- c(0.8,1.8,3.8,5.8,8.8,9.8)
b$order <- a$order + .4
c$order <- c(3,5,7,11)

# add partyID variable
a$Support <- "Affectedness-based fairness: High"
b$Support <- "Affectedness-based fairness: Low"
c$Support <- "Difference"

mydata <- rbind(a,b,c)
mydata$order <- mydata$order * -1 + 12


mydata$Support <- as.factor(mydata$Support)
mydata$Support <- factor(mydata$Support, levels = c(levels(mydata$Support)[1],levels(mydata$Support)[2],levels(mydata$Support)[3]))

xlabelsN <- c(expression(paste(Delta, " 5 Fatalities")), "5", "0", "Number of Fatalities:     ", expression(paste(Delta, " $24 million")), "$24 million", expression(paste(Delta, " $4 million")), "$4 million", expression(paste(Delta, " $1 million")), "$1 million", "$100,000", "Economic Damage:      ")

p <- ggplot(mydata, aes(x=order, y=pe, colour=Support)) + 
  geom_point(aes(x = order, y = pe, colour = Support), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T, size=1) 
p <- p + coord_flip(ylim = c(-1, 2), xlim = c(1, 12)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,12,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)",
                            breaks = c(-1,-0.5,0,0.5,1,1.5,2))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig3 <- p + theme(legend.position = c(.80, 0.95),
               legend.background = element_rect(fill="transparent"),
               legend.key = element_blank(), axis.text = element_text(size = 15)) + scale_colour_grey(name = "") 

fig3
ggsave("Figure3_Affectedness.pdf", width=9, height=8)

###########################################################
# Figure 4: Need-based fairness: High vs. Low
model.a <- c("olsneed_norm_a.txt")
a <- read.table(model.a,header=TRUE)
a <- a[7:13,]
a$ord <- 1:nrow(a)
new_row <- c(0,0)
a <- rbind(a, new_row)
a <- a[order(a$ord),]
a <- a[,-c(3)]

model.b <- c("olsneed_norm_d.txt")
b <- read.table(model.b,header=TRUE)
b <- b[7:13,]
b$ord <- 1:nrow(b)
new_row <- c(0,0)
b <- rbind(b, new_row)
b <- b[order(b$ord),]
b <- b[,-c(3)]

c <- read.xlsx("olsneed_diff.xlsx", sheetIndex = 1)
rownames(c) <- c$NA.
c <- c[,c(2,3)]
c <- c[c(14,20,26,34,36,38),]

# calculate standard errors
a$r1 <- sqrt(a$r1)
b$r1 <- sqrt(b$r1)
c$r1 <- sqrt(c$r1)

# calculate confidence intervals
a$lower <- a$y1  - 1.96*a$r1
a$upper <- a$y1  + 1.96*a$r1

b$lower <- b$y1  - 1.96*b$r1
b$upper <- b$y1  + 1.96*b$r1

c$lower <- c$y1  - 1.96*c$r1
c$upper <- c$y1  + 1.96*c$r1

colnames(a) <- c("pe", "se", "lower", "upper")
colnames(b) <- c("pe", "se", "lower", "upper")
colnames(c) <- c("pe", "se", "lower", "upper")

# add order variable 
a$order <- c(0.8,1.8,3.8,5.8,8.8,9.8,11.8,13.8)
b$order <- a$order + .4
c$order <- c(3,5,7,11,13,15)

# add group variable
a$Support <- "Need-based fairness: High"
b$Support <- "Need-based fairness: Low"
c$Support <- "Difference"


mydata <- rbind(a,b,c)
mydata$order <- mydata$order * -1 + 16


mydata$Support <- as.factor(mydata$Support)
mydata$Support <- factor(mydata$Support, levels = c(levels(mydata$Support)[2],levels(mydata$Support)[3],levels(mydata$Support)[1]))

xlabelsN <- c(expression(paste(Delta, " 9%")),"9%", expression(paste(Delta, " 7%")), "7%",
              expression(paste(Delta, " 5%")), "5%", "3%", "Unemployment Rate:                  ", 
              expression(paste(Delta, " $10,000")), "$10,000",expression(paste(Delta, " $40,000")),
              "$40,000", expression(paste(Delta, " $70,000")), "$70,000", 
              "$100,000", "Average Household Income:       ")

p <- ggplot(mydata, aes(x=order, y=pe, colour=Support)) + 
  geom_point(aes(x = order, y = pe, colour = Support), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T, size=1) 
p <- p + coord_flip(ylim = c(-0.6, 1.2), xlim = c(1, 16)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,16,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)",
                            breaks = c(-0.6,-0.3,0,0.3,0.6,0.9,1.2))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig4 <- p + theme(legend.position = c(.80, 0.95),
                   legend.background = element_rect(fill="transparent"),
                   legend.key = element_blank(), axis.text = element_text(size = 15)) + scale_colour_grey(name = "") 

fig4
ggsave("Figure4_Need.pdf", width=9, height=8)


###########################################################
# Figure 5A: Electorally based fairness: High vs. Low (Democratic President)
model.a <- c("ols_dem_high.txt")
a <- read.table(model.a,header=TRUE)
a <- a[14:18,]

model.b <- c("ols_dem_low.txt")
b <- read.table(model.b,header=TRUE)
b <- b[14:18,]

c <- read.xlsx("olselec_fair_diff.xlsx", sheetIndex = 1)
rownames(c) <- c$NA.
c <- c[,c(2,3)]
c <- c[c(24,26,28,30),]

# calculate standard errors
a$r1 <- sqrt(a$r1)
b$r1 <- sqrt(b$r1)
c$r1 <- sqrt(c$r1)

# calculate confidence intervals
a$lower <- a$y1  - 1.96*a$r1
a$upper <- a$y1  + 1.96*a$r1

b$lower <- b$y1  - 1.96*b$r1
b$upper <- b$y1  + 1.96*b$r1

c$lower <- c$y1  - 1.96*c$r1
c$upper <- c$y1  + 1.96*c$r1

colnames(a) <- c("pe", "se", "lower", "upper")
colnames(b) <- c("pe", "se", "lower", "upper")
colnames(c) <- c("pe", "se", "lower", "upper")

# add order variable 
a$order <- c(0.8,1.8,3.8,5.8,7.8)
b$order <- a$order + .4
c$order <- c(3,5,7,9)

# add partyID variable
a$Support <- "Electorally-based fairness: High"
b$Support <- "Electorally-based fairness: Low"
c$Support <- "Difference"


mydata <- rbind(a,b,c)
mydata$order <- mydata$order * -1 + 10

xlabelsN <- c(expression(paste(Delta, " 70% Democrat, 30% Republican")), "70% Democrat, 30% Republican", 
              expression(paste(Delta, " 60% Democrat, 40% Republican")), "60% Democrat, 40% Republican", 
              expression(paste(Delta, " 30% Democrat, 70% Republican")), "30% Democrat, 70% Republican", 
              expression(paste(Delta, " 40% Democrat, 60% Republican")), "40% Democrat, 60% Republican", 
              "50% Democrat, 50% Republican", "Presidential Vote in 2012:            ")

mydata$Support <- as.factor(mydata$Support)
mydata$Support <- factor(mydata$Support, levels = c(levels(mydata$Support)[2],levels(mydata$Support)[3],levels(mydata$Support)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=Support)) + 
  geom_point(aes(x = order, y = pe, colour = Support), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T, size=1) 
p <- p + coord_flip(ylim = c(-0.6, 0.6), xlim = c(1, 10)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,10,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)",
                            breaks = c(-0.6,-0.4,-0.2,0,0.2,0.4,0.6))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig5A <- p + theme(legend.position = c(.80, 0.95),
                   legend.background = element_rect(fill="transparent"),
                   legend.key = element_blank(), axis.text = element_text(size = 15)) + scale_colour_grey(name = "") 

fig5A
ggsave("Figure5A_ElecFairness_Dem.pdf", width=10, height=8)


###########################################################
# Figure 5B: Electorally based fairness: High vs. Low (Republican President)
model.a <- c("ols_rep_high.txt")
a <- read.table(model.a,header=TRUE)
a <- a[14:18,]

model.b <- c("ols_rep_low.txt")
b <- read.table(model.b,header=TRUE)
b <- b[14:18,]

c <- read.xlsx("olselec_fair_diff1.xlsx", sheetIndex = 1)
rownames(c) <- c$NA.
c <- c[,c(2,3)]
c <- c[c(24,26,28,30),]

# calculate standard errors
a$r1 <- sqrt(a$r1)
b$r1 <- sqrt(b$r1)
c$r1 <- sqrt(c$r1)

# calculate confidence intervals
a$lower <- a$y1  - 1.96*a$r1
a$upper <- a$y1  + 1.96*a$r1

b$lower <- b$y1  - 1.96*b$r1
b$upper <- b$y1  + 1.96*b$r1

c$lower <- c$y1  - 1.96*c$r1
c$upper <- c$y1  + 1.96*c$r1

colnames(a) <- c("pe", "se", "lower", "upper")
colnames(b) <- c("pe", "se", "lower", "upper")
colnames(c) <- c("pe", "se", "lower", "upper")

# add order variable 
a$order <- c(0.8,1.8,3.8,5.8,7.8)
b$order <- a$order + .4
c$order <- c(3,5,7,9)

# add partyID variable
a$Support <- "Electorally-based fairness: High"
b$Support <- "Electorally-based fairness: Low"
c$Support <- "Difference"


mydata <- rbind(a,b,c)
mydata$order <- mydata$order * -1 + 10

xlabelsN <- c(expression(paste(Delta, " 70% Democrat, 30% Republican")), "70% Democrat, 30% Republican", 
              expression(paste(Delta, " 60% Democrat, 40% Republican")), "60% Democrat, 40% Republican", 
              expression(paste(Delta, " 30% Democrat, 70% Republican")), "30% Democrat, 70% Republican", 
              expression(paste(Delta, " 40% Democrat, 60% Republican")), "40% Democrat, 60% Republican", 
              "50% Democrat, 50% Republican", "Presidential Vote in 2012:            ")

mydata$Support <- as.factor(mydata$Support)
mydata$Support <- factor(mydata$Support, levels = c(levels(mydata$Support)[2],levels(mydata$Support)[3],levels(mydata$Support)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=Support)) + 
  geom_point(aes(x = order, y = pe, colour = Support), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T, size=1) 
p <- p + coord_flip(ylim = c(-0.6, 0.6), xlim = c(1, 10)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,10,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)",
                            breaks = c(-0.6,-0.4,-0.2,0,0.2,0.4,0.6))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig5B <- p + theme(legend.position = c(.80, 0.95),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 15)) + scale_colour_grey(name = "") 

fig5B
ggsave("Figure5B_ElecFairness_Rep.pdf", width=10, height=8)

###########################################################
# Figure 6: Partisan identification and government partisanship
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.a <- c("olspres_dem_dem.txt")
a <- read.table(model.a,header=TRUE)
new_row <- c(0,0)
a <- rbind(a, new_row)
a$ord <- 1:nrow(a)
a$ord[a$ord==20] <- 6.5
a <- a[order(a$ord),]
a <- within(a, rm(ord))

model.b <- c("olspres_rep_rep.txt")
b <- read.table(model.b,header=TRUE)
new_row <- c(0,0)
b <- rbind(b, new_row)
b$ord <- 1:nrow(b)
b$ord[b$ord==20] <- 6.5
b <- b[order(b$ord),]
b <- within(b, rm(ord))

# Drop the constants
a <- a[-c(nrow(a)), ]
b <- b[-c(nrow(b)), ]

# calculate standard errors
a$r1 <- sqrt(a$r1)
b$r1 <- sqrt(b$r1)

# calculate confidence intervals
a$lower <- a$y1  - 1.96*a$r1
a$upper <- a$y1  + 1.96*a$r1

b$lower <- b$y1  - 1.96*b$r1
b$upper <- b$y1  + 1.96*b$r1

colnames(a) <- c("pe", "se", "lower", "upper")
colnames(b) <- c("pe", "se", "lower", "upper")

# add order variable 
a$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
b$order <- a$order + .4

# add variable to frames
a$variables <- variables
b$variables <- variables

# add dimension variable
a$pres <- "Dem. with a Dem. president"
b$pres <- "Rep. with a Rep. president"

mydata <- rbind(a,b)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

p <- ggplot(mydata, aes(x=order, y=pe, colour=pres)) + 
  geom_point(aes(x = order, y = pe, colour = pres), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.5, 2), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig6 <- p + theme(legend.position = c(.8, 0.965),
               legend.background = element_rect(fill="transparent"),
               legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 
fig6

# save the plot
ggsave("Figure6_Pres_Res_Partisanship.pdf", width=9, height=8)

###########################################################
# Figure 7: Observed vs. preferred Allocation
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

# Load empirical results
model.empirical <- c("empirical_results.txt")
empirical <- read.table(model.empirical,header=TRUE)
new_row <- c(0,0)
empirical <- rbind(empirical, new_row)
empirical$ord <- 1:nrow(empirical)
empirical$ord[empirical$ord==34] <- 6.5
empirical <- empirical[order(empirical$ord),]
empirical <- within(empirical, rm(ord))

# Load conjoint results
model.conjoint <- c("olscon_main.txt")
conjoint <- read.table(model.conjoint,header=TRUE)
new_row <- c(0,0)
conjoint <- rbind(conjoint, new_row)
conjoint$ord <- 1:nrow(conjoint)
conjoint$ord[conjoint$ord==20] <- 6.5
conjoint <- conjoint[order(conjoint$ord),]
conjoint <- within(conjoint, rm(ord))

#Drop unnecessary observations
empirical <- empirical[-c(34,33,32,31,30,29,28,27,26,25,24,23,22,21,20),]
conjoint <- conjoint[-c(nrow(conjoint)), ]

#calculate standard errors
empirical$r1 <- sqrt(empirical$r1)
conjoint$r1 <- sqrt(conjoint$r1)

#calculate confidence intervals
empirical$lower <- empirical$y1  - 1.96*empirical$r1
empirical$upper <- empirical$y1  + 1.96*empirical$r1

conjoint$lower <- conjoint$y1  - 1.96*conjoint$r1
conjoint$upper <- conjoint$y1  + 1.96*conjoint$r1


colnames(empirical) <- c("pe", "se", "lower", "upper")
colnames(conjoint) <- c("pe", "se", "lower", "upper")

#add order variable 
empirical$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
conjoint$order <- empirical$order + .4

#add variable to frames
empirical$variables <- variables
conjoint$variables <- variables

#add estimate type
empirical$Alloc <- "Observed Allocation"
conjoint$Alloc <- "Preferred Allocation"

mydata <- rbind(conjoint, empirical)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("Opp. Stronghold / 70% Opp., 30% Core", "Opposition / 60% Opp., 40% Core", "Core Stronghold / 70% Core, 30% Opp.", "Core / 60% Core, 40% Opp.", "Swing / 50% D, 50% R", "Presidential Vote in 2012:           ", "7%-36% / 9%", "5%-7% / 7%", "4%-5% / 5%", "0%-4% / 3%", "Unemployment Rate:                  ", "$0k-$29K / $10K", "$29K-$34K / $40K", "$34K-$40K / $70K", "$40K-$104K / $100K", "Average Household Income:       ", "More than 0 / 5", "0 / 0", "Number of Fatalities:                   ", "$10.9M-$29.9B / $24M", "$2M-$11M / $4M", "$400K-$2M / $1M", "$0-$400K / $100K", "Economic Damage:                    ")

mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)

p <- ggplot(mydata, aes(x=order, y=pe, colour=Alloc)) + 
  geom_point(aes(x = order, y = pe, colour = Alloc), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-60, 90), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (in %)",
                            breaks = c(-60,-30,0,30,60,90))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig7 <- p + theme(legend.position = c(.83, 0.965),
               legend.background = element_rect(fill="transparent"),
               legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 
fig7

ggsave("Figure7_Observed_Preferred.pdf", width=9, height=8)

















